package com.ziytek.web.citizen;


import java.io.IOException;
import java.net.ServerSocket;

/**
 * 端口占用检测
 *
 * @author fenghx
 */
public class PortCheckerUtil {
    public static boolean isPortInUse(int port) {
        try (ServerSocket serverSocket = new ServerSocket(port)) {
            serverSocket.setReuseAddress(true);
            // 没有异常发生，端口未被占用
            return false;
        } catch (IOException e) {
            // 捕获异常，端口被占用
            return true;
        }
    }
}
